import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:share_fit/app/components/back_btn_icon.dart';
import 'package:share_fit/app/components/calendar_btn_icon.dart';
import 'package:share_fit/app/helper/ext/tr_ext.dart';
import 'package:share_fit/generated/locales.g.dart';

import 'logic.dart';

class BodyTemperaturePage extends StatelessWidget {
  BodyTemperaturePage({Key? key}) : super(key: key);

  final logic = Get.find<BodyTemperatureLogic>();
  final state = Get.find<BodyTemperatureLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: BackBtnIcon(onTap: () => logic.goBack()),
        actions: [
          CalendarBtnIcon(onTap: () => Get.dialog(_buildShowDatePicker(context))),
        ],
      ),
      body: Container(
        padding: EdgeInsets.only(left: 40.w, right: 40.w, bottom: 90.h),
        child: ListView(
          children: [
            SizedBox(height: 96.h),
            _buildResentTemperatureContainer(),
            SizedBox(height: 99.h),
            _buildHistoryContainer(),
            SizedBox(height: 40.h),
          ],
        ),
      ),
    );
  }

  _buildResentTemperatureContainer() {
    return Column(
      children: [
        Text('近期体温', style: TextStyle(fontSize: 48.sp)),
        Text('36.5', style: TextStyle(fontSize: 120.sp)),
      ],
    );
  }

  _buildHistoryContainer() {
    return Column(
      // crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          children: [
            Container(
              width: 15.w,
              height: 60.w,
              decoration: BoxDecoration(color: Colors.blue, borderRadius: BorderRadius.circular(20.r)),
            ),
            SizedBox(width: 15.w),
            Text('体温记录', style: TextStyle(fontSize: 48.sp)),
          ],
        ),
        SizedBox(height: 60.h),
        ListView.separated(
          shrinkWrap: true,
          physics: const NeverScrollableScrollPhysics(),
          itemBuilder: (context, index) => Container(
            height: 185.w,
            decoration: BoxDecoration(color: Colors.white70.withOpacity(0.8), borderRadius: BorderRadius.circular(40.r)),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                Text('00:00', style: TextStyle(fontSize: 48.sp)),
                Row(
                  children: [
                    Container(
                      width: 68.w,
                      height: 68.w,
                      decoration: BoxDecoration(color: Colors.grey, borderRadius: BorderRadius.circular(100.r)),
                    ),
                    SizedBox(width: 40.w),
                    Text('36.5', style: TextStyle(fontSize: 54.sp)),
                  ],
                ),
                Text('01/11', style: TextStyle(fontSize: 48.sp)),
              ],
            ),
          ),
          separatorBuilder: (context, index) => SizedBox(height: 30.h),
          itemCount: 2,
        )
      ],
    );
  }

  Widget _buildShowDatePicker(BuildContext context) {
    final currentDate = DateTime.now();
    return DatePickerDialog(
      initialDate: currentDate,
      // 初始化选中日期
      firstDate: DateTime(currentDate.year - 1),
      // 开始日期
      lastDate: DateTime(currentDate.year, currentDate.month + 1, currentDate.month - 1),
      // 结束日期
      initialEntryMode: DatePickerEntryMode.calendarOnly,
      // 日历弹框样式

      currentDate: currentDate,
      // 当前日期
      cancelText: LocaleKeys.cancel.ts,
      // 取消按钮文案
      confirmText: LocaleKeys.ok.ts, // 确认按钮文案
    );
  }
}
